/**
 * @brief TCP客户端的接口定义
 * @version 1.0
 * @author 宋炜
 * @date 2023-9-11
 */

#pragma once

#include <functional>
#include <string>

struct itfcSocket
{
#if defined( WINNT ) || defined( WIN32 )
#include <windows.h>
	using native_socket = HANDLE;
#elif defined( __LINUX__ )
	using native_socket = int;
#endif
	virtual bool connect( ) = 0;
	/**
	 * @brief 这个函数处理标准URL连接方式
	 */
	virtual bool connect( const std::string& url ) = 0;
	virtual bool connect( const std::string& url , uint16_t port ) = 0;
	virtual size_t send( const uint8_t * data , size_t len ) = 0;
	virtual void close() = 0;
	virtual void onRecv( std::function< void ( native_socket fd ) > fun ) = 0;
	virtual void onData( std::function<void( const uint8_t * data , size_t len )> fun ) = 0;
	virtual void run( bool sw ) = 0;

	virtual native_socket getHandle() = 0;
};
